package rmicomplex;

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Master extends Frame implements MasterInterface
{
	public Master() throws RemoteException {
		setBounds(100, 200, 50, 20);
		setVisible(true);
		setTitle("Servidor");
		
		addWindowListener( 
				new WindowAdapter()
				{
					public void windowClosing(WindowEvent e)
					{
						try
						{
							Naming.unbind( "//localhost:20005/aServ");
							System.out.println("unbind() ...");
							System.exit(1);
						}
						catch(Exception err)
						{ 
							err.printStackTrace(); 
						}
					}
				}
			);
			try {
				UnicastRemoteObject.exportObject(this);
				Naming.bind( "//localhost:20005/aServ", this);
				System.out.println("bind()...");
			}
			catch(Exception e) {
				e.printStackTrace(); 
			}
	}

	public void setClientInterface( ClientInterface cli)
		throws RemoteException
	{
		(new unClient(cli)).start();
	}
	
	public static void main(String args[]) throws Exception
	{
		new Master();
	}
}